import store from '../store/index';

export default async function (to, from, next) {
    let userRole = store.getters.getUserRole;
    if (userRole == null) {
        let res = await store.dispatch('getLoginInfo');
        userRole = res.data.role;
        if (res.statusCode == 0) {
            return next({ name: "Login" });
        }

    }
    
    if (to.matched[0].path == "/admin" && userRole.is_to_back == 0) {//是否允许进入后台
        console.error("拒绝访问");
        return next({ name: "Home" });
    }

    next();
}